package com.ntd.study.modular.hutool.proxy;

import cn.hutool.aop.aspects.SimpleAspect;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;

import java.lang.reflect.Method;

public class TimeIntervalAspect extends SimpleAspect {

    private TimeInterval interval = new TimeInterval();

    @Override
    public boolean before(Object target, Method method, Object[] args) {
        interval.start();
        return true;
    }

    @Override
    public boolean after(Object target, Method method, Object[] args, Object returnVal) {
        Console.log("方法 [{}.{}] 执行耗时 {}ms", target.getClass().getName(), method.getName(), interval.intervalMs());
        return true;
    }
}